#define  _CRT_SECURE_NO_WARNINGS



#include<stdio.h>
#include<string.h>


char arr[1000][21] = { 0 }, str[1000] = { 0 };
int main()
{
    int n = 0, i = 0, len = 0, j = 0, k = 0, len2 = 0, a = 0, b = 0, sum = 0;
    scanf("%d", &n);
    getchar();
    for (i = 0; i < n; i++)
    {
        scanf("%s", arr[i]);
    }
    getchar();
    while (gets(str) != NULL)
    {
        char temp[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        char* c[100] = { 0 };
        c[0] = strtok(str, " ");
        i = 0;
        while (c[i] != NULL)
        {
            c[++i] = strtok(NULL, " ");
        }
        for (j = 0; j < i; j++)
        {
            for (k = 0; k < n; k++)
            {
                if (c[j][0] == arr[k][0] || c[j][0] == arr[k][0] + 32 || c[j][0] == arr[k][0] - 32)
                {
                    len = strlen(arr[k]);
                    sum = 0;
                    if (len == strlen(c[j]))
                    {
                        for (a = 0; a < len; a++)
                        {
                            if (c[j][a] == arr[k][a] || c[j][a] == arr[k][a] + 32 || c[j][a] == arr[k][a] - 32)
                                sum++;
                        }
                    }
                    if (sum == len)
                    {
                        for (a = 1; a < len; a++)
                        {
                            c[j][a] = '*';
                        }
                        break;
                    }
                }
            }
        }
        for (j = 0; j < i; j++)
        {
            len = strlen(c[j]);
            printf("%s ", c[j]);
        }
        printf("\n");
    }

    return 0;
}